<?php
class DynamicFindExpenseAction extends CAction {
	public function run($barcode){
		$expense=Yii::app()->codeManager->findModel($barcode);
		if(!is_a($expense, 'MaterialExpense')){
			throw new CHttpException(404);
		}
		$returnValue=array(
			'id'=>$expense->id,
			'accountTokenId' => $expense->accountTokenId,
			'totalPrice' => Yii::app()->format->formatCurrency($expense->totalPrice),
			'expenseDate' => $expense->expenseDate,
			'externalTokenDate' => $expense->externalTokenDate,
			'externalTokenNumber' => $expense->externalTokenNumber,
			'receiptCount' => $expense->receiptCount,
			'project' => array(
				'name' => $expense->project->name
			),
		);
		echo CJSON::encode($returnValue);
	}
}
